package behaviour;

import java.util.Collections;
import java.util.List;

import maze.Coordinate;
import maze.Direction;
import maze.Location;
import maze.Maze;

public class MazeCorrector implements Strategy {
	private Maze maze;
	private Coordinate currentCoordinate;
	private Direction previousDirection;
	public MazeCorrector(Maze maze){
		this.maze=maze;
		previousDirection=Direction.NORTH;
	}
	@Override
	public Direction nextDirection(Location loc, Maze[] mazes, Coordinate[] ghosts) {
		currentCoordinate=maze.getCoordinateOfLocation(loc);
		List<Direction> directions=maze.getClearDirections(currentCoordinate.getX(),currentCoordinate.getY(),true);
		if(directions.contains(previousDirection.right())){
			Direction result=previousDirection.right();
			previousDirection=result;
			return result;
		}
		else if(directions.contains(previousDirection))
			return previousDirection;
		else if(directions.contains(previousDirection.left())){
			Direction result=previousDirection.left();
			previousDirection=previousDirection.left();
			return result;
		}
		Direction result=previousDirection.opposite();
		previousDirection=previousDirection.opposite();
		return result;
	}
	@Override
	public boolean exploreEverything() {
		// TODO Auto-generated method stub
		return true;
	}
	@Override
	public void setCoordinatePacman(Coordinate coordinate) {
		// TODO Auto-generated method stub
		
	}

}
